<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-09-11 08:37:19
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-09-17 16:51:36
 * @FilePath: \23WRX\city\src\pages\components\Left1.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        <!-- 提供图表容器 -->
        <div ref="bottom3" style="height: 150px;"></div>
    </div>
</template>
<script>
import { get } from '@/utils/request';
import { Area } from '@antv/g2plot';
import moment from 'moment';
import { mapState } from 'vuex';
export default {
    data() {
        return {
            title: '噪音监控',
            params:{
                page:1,
                pageSize:100
            },
            areaData:[],
            area: null
        }
    },
     computed: {
        ...mapState(['ed'])
    },
    //侦听器 侦听数据
    watch: {
        ed: {
            handler(n, o) {
                //根据设备信息 重新查询数据 重新渲染图表
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getAreaData();
                //根据最新获取的数据
                this.area.changeData(this.areaData);
            },
            //深度侦听
            deep: true
        }
    },
    methods: {
        loadLine() {
            this.area = new Area(this.$refs.bottom3, {
                data: this.areaData,
                xField: 'insert_time',
                yField: 'noise',
                xAxis: {
                    range: [0, 1],
                    tickCount: 5,
                },
                areaStyle: () => {
                    return {
                        fill: 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff',
                    };
                }
            })
            this.area.render();
        },
        //封装方法获得后端接口的实时数据
        async getAreaData() {
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            console.log(res, "2222222");
            let temp = [];
            //将后端获取的数据给
            res.data.list.forEach((item, index, arr) => {
                arr[0].noise = 0;
                //由于刻度混乱
                //item表示数组每一项
                item.insert_time = moment(item.insert_time).format("HH:mm");
                //每隔十条取一条
                if (index % 10 == 0) {
                    temp.push(arr[index])
                }
            });
            this.areaData = temp;
        }
    },
    async mounted() {
        await this.getAreaData();
        this.loadLine();
    }
}
</script>
<style lang="less" scoped></style>